﻿using System.ComponentModel;
using System.Windows;
using WikiUploader.Classes;

namespace WikiUploader.Controls
{
   /// <summary>
   /// Interaction logic for LogView.xaml
   /// </summary>
   public partial class LogView
   {
      /// <summary>
      /// Initializes a new log view object.
      /// </summary>
      public LogView ()
      {
         InitializeComponent ();
      }

      /// <summary>
      /// Occurs when the control is loaded.
      /// </summary>
      /// <param name="sender">This control.</param>
      /// <param name="e">RoutedEventArgs</param>
      private void LogViewLoaded (object sender, RoutedEventArgs e)
      {
         var dataContext = this.DataContext as LogViewModel;
         if (dataContext != null)
         {
            dataContext.PropertyChanged += LogChanged;
         }
      }
      
      /// <summary>
      /// Occurs when a property in the log data context has changed.
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void LogChanged (object sender, PropertyChangedEventArgs e)
      {
         MainViewModel.SyncContex.Post (delegate { this._LogTextBox.ScrollToEnd (); }, null);
      }
   }
}
